package com.zjw.algorithm.epoll_mock;

public class Test {

    public static void main(String[] args) {
        IEventQueue eventQueue = new SimpleEventQueue();


        new Thread(() -> {
            for (int i = 0; i < 1; i++) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }

                Event event = new Event();
                event.what = 0;
                System.out.println(System.currentTimeMillis() + " 发送事件 " + 0);
                event.time = 2000;
                eventQueue.enqueue(event);

                Event event2 = new Event();
                event2.what = 1;
                System.out.println(System.currentTimeMillis() + " 发送事件 " + 1);
                eventQueue.enqueue(event2);
            }
        }).start();


        System.out.println("start wait");
        while (true) {
            Event event = eventQueue.waitEvent();
            if (event != null) {
                System.out.println(System.currentTimeMillis() + " receive event " + event.what);
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
}
